package com.wanxi.education.service.impl;

import com.wanxi.education.mapper.UserMapper;
import com.wanxi.education.model.vo.user.CUserRegisterVo;
import com.wanxi.education.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: YanZhengYi
 * @Description:
 * @Date: Created in 2021/9/24
 * @Version: 1.0
 */
@Service
public class RegisterServiceImpl implements RegisterService {

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Autowired
    private UserMapper userMapper;

    @Override
    @Transactional
    public Integer cRegister(CUserRegisterVo cUserRegisterVo) {
        cUserRegisterVo.setPassword(passwordEncoder.encode(cUserRegisterVo.getPassword()));
        Integer result = userMapper.cRegister(cUserRegisterVo);
        List<Integer> ids = new ArrayList<>();
        ids.add(4);
        userMapper.insertRole(ids,cUserRegisterVo.getId());
        return result;
    }
}
